package com.jctrip.hotel.source.xxl.rezen.thread;

import org.apache.commons.lang.StringUtils;

import com.jctrip.hotel.common.constant.RedisKeyConstant;
import com.jctrip.hotel.common.context.BeanContext;
import com.jctrip.hotel.common.util.RedisUtil;
import com.jctrip.hotel.source.service.rezen.RezenTaskService;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author henry
 * @Date 2023/8/12 11:43
 * @Description
 */
@Slf4j
public class SyncRezenHotelListPullThread implements Runnable {
    private final String secretId;
    private final String secretKey;
    private final Long groupId;

    public SyncRezenHotelListPullThread(String secretId, String secretKey, Long groupId) {
        this.secretId = secretId;
        this.secretKey = secretKey;
        this.groupId = groupId;
    }

    @Override
    public void run() {
        try {
            RedisUtil redisUtil = BeanContext.getApplicationContext().getBean(RedisUtil.class);
            RezenTaskService rezenTaskService = BeanContext.getApplicationContext().getBean(RezenTaskService.class);
            while (redisUtil.lGetListSize(RedisKeyConstant.HOTEL_MAIN_REZEN_CITYID_LIST) > 0) {
                try {
                    Long hotelId = ((Number) redisUtil.rightPop(RedisKeyConstant.HOTEL_MAIN_REZEN_CITYID_LIST)).longValue();
                    if (hotelId == null) {
                        continue;
                    }
                    rezenTaskService.syncRezenCityListTaskPull(secretId, secretKey, groupId, hotelId);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
